#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


int main()
{
    return 0;
    /*获取套接字*/
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
        return -1;
    }

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(8080);
    addr.sin_addr.s_addr = inet_addr("0.0.0.0");  /*将ipv4转化为长整型*/
    socklen_t len = sizeof(struct sockaddr_in);   /*计算一下sockaddr_in的类型, 然后为了后面的绑定*/
    
    int ret = bind(sockfd, (sockaddr*)&addr, len);
    if (ret < 0)
    {
        return -1;
    }

    ret = listen(sockfd, 5);  /*第二个参数是套接字排队的最大连接数*/ /*监听*/
    if (ret < 0)
    {
        perror("listen error");
        return -1;
    }
    while (1)
    {
        /*接受套接字*/
        int newfd = accept(sockfd, NULL, 0);    /*循环接受套接字*/
        if (newfd < 0)
        {
            perror("accept error");
            return -1;
        }
        //
        char buf[1024] = { 0 };
        int ret = recv(newfd, buf, 1024, 0);     /*接收数据*/
        if (ret < 0)
        {
            close(newfd);
            continue;
        }
        else if(ret == 0)
        {
            close(newfd);
            continue;
        }

        std::string body = "<html><body><h1>Hello World</h1></body></html>";
        std::string rsp = "HTTP/1.1 200 OK\r\n";
            /*发送*/




            /*关闭连接*/
    }

}